module.exports = (app) => {
    const mongoose = app.mongoose;
    const Schema = mongoose.Schema;

    const subCommentSchema = new Schema(
        {
            replyedPerson: { // 被回复的人
                nickname: {type: String, required: true},
                avatar: {type: String, required: false, default: "/user.jpg"},
                id: {
                    type: Schema.Types.ObjectId,
                    ref: "User",
                    required: true,
                }
            },
            article: {
                type: Schema.Types.ObjectId,
                ref: "Article",
                required: true,
            },
            commitPerson: { // 回复的人
                nickname: {type: String, required: true},
                avatar: {type: String, required: false, default: "/user.jpg"},
                id: {
                    type: Schema.Types.ObjectId,
                    ref: "User",
                    required: true,
                }
            },
            // 评论内容
            commentText: {type: String, required: true},
        },
        {timestamps: true}
    );

    const CommentSchema = new Schema(
        {
            replyedPerson: { // 被回复的人
                type: Schema.Types.ObjectId,
                ref: "User",
                required: false,
            },
            article: {
                type: Schema.Types.ObjectId,
                ref: "Article",
                required: true,
            },
            commitPerson: { // 回复的人
                type: Schema.Types.ObjectId,
                ref: "User",
                required: false,
            },
            // 评论内容
            commentText: {type: String, required: true},
            // subComments: {type: [{type: Schema.Types.ObjectId, ref: "Comment"}]},
            subComments: {type: [subCommentSchema]},
        },
        {timestamps: true}
    );
    return mongoose.model("Comment", CommentSchema);
};
